import os
import uuid

from app.core.config import settings

from langfuse.llama_index import LlamaIndexCallbackHandler

#理论上可以方便动态更改 trace_name和user_id,session_id
langfuse_callback_handler = LlamaIndexCallbackHandler(
    trace_name='aip',
    user_id='aip',
    session_id=str(uuid.uuid1()),
    public_key=settings.LANGFUSE_PUBLIC_KEY,
    secret_key=settings.LANGFUSE_SECRET_KEY,
    host=settings.LANGFUSE_URL
)


def init_or_startup():
    from llama_index.core import Settings
    from llama_index.core.callbacks import CallbackManager, LlamaDebugHandler
    llama_debug = LlamaDebugHandler(print_trace_on_end=True)

    # Settings.callback_manager = CallbackManager([langfuse_callback_handler,llama_debug])
    Settings.callback_manager = CallbackManager([langfuse_callback_handler])
